﻿using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using VioletDevelopmentLaboratory.Net.Web;
using VioletDevelopmentLaboratory.Net.Web.Component;

public partial class vboard_membership_profile : VioletDevelopmentLaboratory.Net.Web.PageBase
{
	protected void PasswordCheckButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			if (Membership.ValidateUser(Page.User.Identity.Name, PasswordTextBox.Text))
			{
				PasswordCheckPanel.Visible = false;
				ModifyPanel.Visible = !PasswordCheckPanel.Visible;

				//birthdayForm();

				//profiles_Bind();

				MembershipUser user = Membership.GetUser();

				LoadImage(user.ProviderUserKey.ToString());
			}
			else
				VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_CheckPassword_Failure"), true);
		}
	}

	private void profiles_Bind()
	{
		/*if (YearDropDownList.Items.FindByValue(Profile.VWeb.Birthday_Year.ToString()) != null)
			YearDropDownList.SelectedValue = Profile.VWeb.Birthday_Year.ToString();
		else
			YearDropDownList.SelectedIndex = -1;

		if (MonthDropDownList.Items.FindByValue(Profile.VWeb.Birthday_Month.ToString()) != null)
			MonthDropDownList.SelectedValue = Profile.VWeb.Birthday_Month.ToString();
		else
			MonthDropDownList.SelectedIndex = -1;

		if (DayDropDownList.Items.FindByValue(Profile.VWeb.Birthday_Day.ToString()) != null)
			DayDropDownList.SelectedValue = Profile.VWeb.Birthday_Day.ToString();
		else
			DayDropDownList.SelectedIndex = -1;

		HomepagesTextBox.Text = Profile.VWeb.Homepages;
		InterestsTextBox.Text = Profile.VWeb.Interests;*/
	}

	private void birthdayForm()
	{
		/*YearDropDownList.Items.Add("");
		for (int i = DateTime.Now.Year - 7; i >= DateTime.Now.Year - 100; i--)
		{
			YearDropDownList.Items.Add(i.ToString());
		}

		MonthDropDownList.Items.Add("");
		for (int i = 1; i < 13; i++)
		{
			MonthDropDownList.Items.Add(i.ToString());
		}
		DayDropDownList.Items.Add("");
		for (int i = 1; i < 32; i++)
		{
			DayDropDownList.Items.Add(i.ToString());
		}*/
	}
	private void DayDropDownList_Bind()
	{
		/*if (!string.IsNullOrEmpty(YearDropDownList.SelectedValue) && !string.IsNullOrEmpty(MonthDropDownList.SelectedValue))
		{
			int days = DateTime.DaysInMonth(int.Parse(YearDropDownList.SelectedValue), int.Parse(MonthDropDownList.SelectedValue));

			DayDropDownList.Items.Clear();
			DayDropDownList.Items.Add("");

			for (int i = 1; i <= days; i++)
			{
				DayDropDownList.Items.Add(i.ToString());
			}
		}*/
	}
	protected void YearDropDownList_SelectedIndexChanged(object sender, EventArgs e)
	{
		//DayDropDownList_Bind();
	}
	protected void MonthDropDownList_SelectedIndexChanged(object sender, EventArgs e)
	{
		//DayDropDownList_Bind();
	}
	protected void ProfileModifyButton_Click(object sender, EventArgs e)
	{
		/*if (!String.IsNullOrEmpty(YearDropDownList.SelectedValue) &&
			!String.IsNullOrEmpty(MonthDropDownList.SelectedValue) &&
			!String.IsNullOrEmpty(DayDropDownList.SelectedValue))
		{
			Profile.VWeb.Birthday_Year = int.Parse(YearDropDownList.SelectedValue);
			Profile.VWeb.Birthday_Month = int.Parse(MonthDropDownList.SelectedValue);
			Profile.VWeb.Birthday_Day = int.Parse(DayDropDownList.SelectedValue);
		}
		else
		{
			Profile.VWeb.Birthday_Year = 0;
			Profile.VWeb.Birthday_Month = 0;
			Profile.VWeb.Birthday_Day = 0;
		}
		Profile.VWeb.Homepages = HomepagesTextBox.Text;
		Profile.VWeb.Interests = InterestsTextBox.Text;

		profiles_Bind();

		VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_ModifyProfile_Success"), true);*/
	}








	private void LoadImage(string providerUserKey)
	{
		UserImage.Visible = true;
		UserImage.ImageUrl = VUtility.GetMemberImageUrl(providerUserKey);
	}
	protected void PictureDeleteButton_Click(object sender, EventArgs e)
	{
		MembershipUser user = Membership.GetUser();

		MemberImageFileInfo.Remove(user.ProviderUserKey.ToString());

		VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_Picture_RemovedImage"), true);
	}
	protected void PictureSaveButton_Click(object sender, EventArgs e)
	{
		if (!string.IsNullOrEmpty(UserImageFileUpload.PostedFile.FileName))
		{
			if (!AttachmentFileManager.IsAllowExtension("gif;jpg;jpeg;png", System.IO.Path.GetFileName(UserImageFileUpload.PostedFile.FileName)))
			{
				VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_Picture_InvalidImageFile"), true);
				return;
			}

			if (UserImageFileUpload.PostedFile.ContentLength > 200 * 1024)
			{
				VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_Picture_ExcessImageFileLength"), true);
				return;
			}

			MembershipUser user = Membership.GetUser();

			MemberImageFileInfo.Add(UserImageFileUpload.PostedFile, user.ProviderUserKey.ToString());

			LoadImage(user.ProviderUserKey.ToString());

			VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_Picture_SavedImage"), true);
		}
		else
		{
			VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_Picture_SelectImageFile"), true);
		}
	}
}
